﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class DuctRoundBeamForm : System.Windows.Forms.Form
	{
		private void GetUserSetting()
		{
			this.hyTextBox1.Enabled = false;
			this.rabPickSel.Checked = true;
			string[] ductAlignTypeText = this.hvacUserSetting.GetDuctAlignTypeText(true);
			string b = ductAlignTypeText[0];
			this.rabBoxSel.Enabled = true;
			if ("Middle" == b)
			{
				this.rdoMiddle.Checked = true;
				if (ductAlignTypeText[1] == "true")
				{
					this.checkBox1.Enabled = true;
					this.checkBox1.Checked = true;
					this.hyTextBox1.Enabled = true;
				}
				else
				{
					this.checkBox1.Checked = false;
				}
			}
			else if ("Top" == b)
			{
				this.rdoTop.Checked = true;
				if (ductAlignTypeText[1] == "true")
				{
					this.checkBox1.Enabled = true;
					this.checkBox1.Checked = true;
					this.hyTextBox1.Enabled = true;
				}
				else
				{
					this.checkBox1.Checked = false;
				}
			}
			else if ("Bottom" == b)
			{
				this.rdoBottom.Checked = true;
				if (ductAlignTypeText[1] == "true")
				{
					this.checkBox1.Enabled = true;
					this.checkBox1.Checked = true;
					this.hyTextBox1.Enabled = true;
				}
				else
				{
					this.checkBox1.Checked = false;
				}
			}
			else if ("Reference" == b)
			{
				this.rdoReference.Checked = true;
				this.checkBox1.Enabled = false;
				this.hyTextBox1.Enabled = false;
				this.rabBoxSel.Enabled = false;
			}
			else
			{
				this.rdoMiddle.Checked = true;
				if (ductAlignTypeText[1] == "true")
				{
					this.checkBox1.Enabled = true;
					this.checkBox1.Checked = true;
					this.hyTextBox1.Enabled = true;
				}
				else
				{
					this.checkBox1.Checked = false;
				}
			}
			if (ductAlignTypeText[2] != "")
			{
				this.hyTextBox1.Text = ductAlignTypeText[2];
			}
			if (ductAlignTypeText[3] == "1")
			{
				this.rabPickSel.Checked = true;
				return;
			}
			this.rabBoxSel.Checked = true;
		}

		private Image getImage(string me)
		{
			return new Bitmap(Image.FromFile(Path.Combine(Product.ResLocation, me + ".png")), this.pictureBoxDQ.Width, this.pictureBoxDQ.Height);
		}

		public void changeImage()
		{
			if (this.rdoTop.Checked)
			{
				this.pictureBoxDQ.Image = this.getImage("DQSJDINGDQ");
			}
			if (this.rdoMiddle.Checked)
			{
				this.pictureBoxDQ.Image = this.getImage("DQSJZXDQ");
			}
			if (this.rdoBottom.Checked)
			{
				this.pictureBoxDQ.Image = this.getImage("DQSJDDQ");
			}
			if (this.rdoReference.Checked)
			{
				this.pictureBoxDQ.Image = this.getImage("DQSJBDQ");
			}
		}

		public DuctRoundBeamForm()
		{
			this.InitializeComponent();
		}

		public DuctRoundBeamForm(IList<XYZ> xyzs)
		{
			this.InitializeComponent();
			this.xyzs = xyzs;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (!Regex.IsMatch(this.hyTextBox1.Text, "^[+-]?[0-9]+\\d*[.]?\\d*$"))
			{
				MessageBox.Show("对齐高度必须为有效数字", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
				this.hyTextBox1.Focus();
				return;
			}
			string[] array = new string[4];
			if (this.rdoMiddle.Checked)
			{
				this.alignmentType = "Middle";
			}
			else if (this.rdoTop.Checked)
			{
				this.alignmentType = "Top";
			}
			else if (this.rdoBottom.Checked)
			{
				this.alignmentType = "Bottom";
			}
			else if (this.rdoReference.Checked)
			{
				this.alignmentType = "Reference";
			}
			array[0] = this.alignmentType;
			if (this.checkBox1.Checked)
			{
				array[1] = "true";
			}
			else
			{
				array[1] = "false";
			}
			if (this.hyTextBox1.Text != "")
			{
				array[2] = this.hyTextBox1.Text;
			}
			if (this.rabBoxSel.Enabled && this.rabBoxSel.Checked)
			{
				this.nselType = 2;
				array[3] = "2";
			}
			else
			{
				this.nselType = 1;
				array[3] = "1";
			}
			this.height = double.Parse(this.hyTextBox1.Text) / 304.8;
			new HVACUserSetting().WriteDuctAlignTypeText(array);
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void DuctRoundBeamForm_Load(object sender, EventArgs e)
		{
			this.GetUserSetting();
			if (this.rdoReference.Checked)
			{
				this.checkBox1.Checked = false;
				this.isUserDate = false;
				this.checkBox1.Enabled = false;
				this.hyTextBox1.Enabled = false;
				this.pictureBoxDQ.Image = this.getImage("DQSJBDQ");
			}
			this.changeImage();
			this.updateFormRadio();
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (this.checkBox1.Checked)
			{
				this.isUserDate = true;
				this.hyTextBox1.Enabled = true;
				return;
			}
			this.isUserDate = false;
			this.hyTextBox1.Enabled = false;
		}

		private void rdoReference_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoReference.Checked)
			{
				this.checkBox1.Enabled = false;
				this.hyTextBox1.Enabled = false;
				this.rabBoxSel.Enabled = false;
				this.rabPickSel.Checked = true;
				this.checkBox1.Checked = false;
			}
			else
			{
				this.checkBox1.Enabled = true;
				if (this.checkBox1.Checked)
				{
					this.hyTextBox1.Enabled = true;
				}
				this.rabBoxSel.Enabled = true;
			}
			this.changeImage();
		}

		private void rdoMiddle_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoBottom.Checked)
			{
				this.checkBox1.Enabled = true;
				if (this.checkBox1.Checked)
				{
					this.hyTextBox1.Enabled = true;
				}
				this.rabBoxSel.Enabled = true;
			}
			this.changeImage();
		}

		private void rdoTop_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoTop.Checked)
			{
				this.checkBox1.Enabled = true;
				if (this.checkBox1.Checked)
				{
					this.hyTextBox1.Enabled = true;
				}
				this.rabBoxSel.Enabled = true;
			}
			this.changeImage();
		}

		private void rdoBottom_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoBottom.Checked)
			{
				this.checkBox1.Enabled = true;
				if (this.checkBox1.Checked)
				{
					this.hyTextBox1.Enabled = true;
				}
			}
			this.changeImage();
		}

		private void radioDuctRoungBeam_CheckedChanged(object sender, EventArgs e)
		{
			this.updateFormRadio();
		}

		private void updateFormRadio()
		{
			if (!this.rdoMiddle.Checked && !this.rdoTop.Checked && !this.rdoBottom.Checked && !this.rdoReference.Checked)
			{
				this.rdoMiddle.Checked = true;
			}
		}

		private void radioAlignment_CheckedChanged(object sender, EventArgs e)
		{
			this.updateFormRadio();
		}

		private HVACUserSetting hvacUserSetting = new HVACUserSetting();

		public double offSet;

		public double angle = 1.0471975511965976;

		private IList<XYZ> xyzs = new List<XYZ>();

		public string alignmentType = "";

		public bool isUserDate;

		public double height;

		public string beamOrAlignment = "";

		public int nselType = 1;
	}
}
